package com.martin.lib_base.net

import com.martin.lib_base.BuildConfig
import com.martin.lib_base.bean.common.BaseResponse
import com.martin.lib_base.bean.common.DictBean
import com.martin.lib_base.bean.common.LoginBean
import com.martin.lib_base.bean.common.SimpleResultBean
import com.martin.lib_base.bean.common.UploadBean
import com.martin.lib_base.net.interceptor.EncryptionAndDecryptionInterceptor
import okhttp3.MultipartBody
import okhttp3.RequestBody
import okhttp3.ResponseBody
import retrofit2.http.*

/**
 * @author：孟凡华
 * @date：2022/11/21
 * @desc：
 */
interface Api {

    companion object {
        const val BASE_URL = BuildConfig.baseUrl
    }

    //================================= 功能接口 ==============================================

    @POST("resource/oss/upload")
    @Headers("pass: skipAddToken")
    @Multipart
    suspend fun uploadFile(
        @Part file: MultipartBody.Part,
        @PartMap map: MutableMap<String, RequestBody>
    ): BaseResponse<UploadBean>

    @GET
    @Streaming
    @Headers("Calldown: download")
    suspend fun download(@Url url: String): ResponseBody

    //================================= 业务接口 ==============================================

    /**
     * 通用请求
     */
    @POST
    suspend fun anyPost(@Url url: String, @Body body: RequestBody): BaseResponse<Any>

    @POST
    suspend fun anyPostPath(@Url url: String): BaseResponse<Any>

    /**
     * 纯字符串值
     */
    @GET
    suspend fun singleStringPost(@Url url: String): BaseResponse<String>

    @POST
    suspend fun simplePost(
        @Url url: String,
        @Body body: RequestBody
    ): BaseResponse<SimpleResultBean>

    @PUT
    suspend fun simplePut(
        @Url url: String,
        @Body body: RequestBody
    ): BaseResponse<SimpleResultBean>

    @GET
    suspend fun simpleGet(
        @Url url: String
    ): BaseResponse<SimpleResultBean>

    /**
     * 获取字典列表
     */
    @GET
    suspend fun getDictList(@Url url: String): BaseResponse<List<DictBean>>

    @POST
    suspend fun postDictList(@Url url: String): BaseResponse<DictBean>

    @GET
    suspend fun getDictListPage(@Url url: String): BaseResponse<DictBean>

    /**
     * 登录
     */
    @Headers("${EncryptionAndDecryptionInterceptor.ENCRYPTED_STATUS_HEADER_KEY}: true")
    @POST("auth/login")
    suspend fun login(@Body body: RequestBody): BaseResponse<LoginBean>

    @GET("/resource/sms/code")
    suspend fun getCode(@Query("phonenumber") phonenumber: String): BaseResponse<SimpleResultBean>

    /**
     * 登出
     */
    @POST("auth/logout")
    suspend fun logout(): BaseResponse<Any>

    /**
     * 获取登录验证码
     */
    @POST("auth/smsCode")
    suspend fun getLoginCode(): BaseResponse<Any>


}